package servlet;

import bean.Article;
import bean.User;
import db.DbFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/user/front.do")
public class FrontServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User) request.getSession().getAttribute("currentUser");
        if (user == null) {
            response.sendRedirect("../login.jsp");
        } else {
            //找出当前用户所有消息，放入request范围
            List<Article> articles = DbFactory.getArticleDao().findByID(user.getId());
            request.setAttribute("articles",articles);
            request.getRequestDispatcher("/WEB-INF/front.jsp").forward(request, response);
        }
    }
}
